﻿using System;
using System.Text;
using AuchanScan.Models;

namespace AuchanScan.ViewModels
{
    public class PayViewModel
    {
        public String GenerateCodeForQRCode()
        {
            var res = new StringBuilder();
            foreach (Achat achat in ViewModelLocator.MainViewModelStatic.Datas.Courses)
            {
                string code = (achat.Product.ShortBarcode ? "1" : "0") +
                              achat.Product.Barcode.ToString("D" + (achat.Product.ShortBarcode ? 8 : 13));

                int nbr = achat.Quantity;
                while (nbr > 9)
                {
                    res.Append("9" + code);
                }
                res.Append(nbr.ToString() + code);
            }

            return res.ToString();
        }
    }
}